function findOrder(needId){
	$(location).attr('href', 'new_file8?needId='+needId+'');
}
function phone(needId){
	$.ajax({
		"url" : Server +"/res/need/phone",
		"type" : "POST",
		"data" : {
			"needId" : needId
		},
	success : function(data){
		var v = data;
		$("#ww1").val(v[0].contacts);
		$("#ww1").attr("disabled","disabled");
		$("#ww2").val(v[0].phone);
		$("#ww2").attr("disabled","disabled");
		$("#ww3").val(v[0].address);
		$("#ww3").attr("disabled","disabled");
	}
	})
}
$(document).ready(function(){
	phone(GetQueryString("needId"));
	
	});
function GetQueryString(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
	var r = window.location.search.substr(1).match(reg);
	if(r != null) return unescape(r[2]);
	return null;
}

var data=[1,2,10,11,12,13,14,15,3];//#result的数据来自这
function getClickIndex(e) {
    var node = e.target;
    var nodearr=node.parentNode.children
    var index= data.indexOf.call(nodearr, node);
    return index;
}
function typeList(){
	$.ajax({
		url : Server +"/fon/infomaxclass",
		type : "post",
		dataType : "JSON",
		async: false,
		success : function(data) {
			var needhtml = "<ul><li typeId="+data[0].tradeId+" class='selected'>"+ data[0].tradeName+"</li>";
			for (var i = 1; i < data.length; i++) {
				needhtml += "<li typeId="+data[i].tradeId+">"+ data[i].tradeName+"</li>";
			}
			needhtml += "</ul>"
			$("#sorts").html(needhtml);
		}
	});
}
function typeDetail(){
	var html1 = $("#tenneed").html();
	var ntypeId = '1';
	var tradeId = '0';
	if($("#tenneed").hasClass("tab2")){
		ntypeId = '1';
	}else if($("#cooneed").hasClass("tab2")){
		ntypeId = '2';
	}else if($("#perneed").hasClass("tab2")){
		ntypeId = '3';
	}
	var tradeId = $(".selected").attr("typeId");
	$.ajax({
		url : Server +"/res/need/listType",
		//url : "http://localhost/res/need/listType",
		type : "post",
		dataType : "JSON",
		data : {
			"offset" : 0,
			"limit" : 10,
			"ntypeId" : ntypeId,
			"tradeId" : tradeId
		},
		success : function(data){
			var m = data.rows;
			var html = "";
			var pattern = '<div id="l_no2_#2" class="item" style="display:block">\
									<div class="item_left"><p>#0</p></div>\
									<div class="item_right">\
										<div class="textInfo">\
											<div class="row1">#1</div>\
											<!--<div class="row2"><span>需求简介：</span>#3</div>-->\
											<div class="row3"><font><span>地址：</span>#4</font><font><span>发布时间：</span>#5</font><font><span>行业类别：</span>#6</font></div>\
											<div class="row4">预算：#7</div>\
										</div>\
										<div class="activBtn">\
											<a onclick="findOrder(#8)">查看详情</a>\
											<a onclick="phone(#9)" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">联系方式</a>\
										</div>\
									</div>\
								</div>';
			var item = "";
			for (var i = 0; i < m.length; i++) {
				var Status = ""; //需求类型0：技术需求1：合作需求2：人才需求
				switch (m[i].ntypeId) {
				case 0:
					Status = "技术需求";
					break;
				case 1:
					Status = "合作需求";
					break;
				case 2:
					Status = "人才需求";
					break;
				}
				if (m[i].needCreateTime != '' || m[i].needCreateTime != null || m[i].needCreateTime != undefined) {
					var Time = (m[i].needCreateTime).substring(0, (m[i].needCreateTime).indexOf(' '));
					item += pattern
						.replace("#0", Status)
						.replace("#1", m[i].needName)
						//.pattern.replace("#2", data[i].)仪器图片链接
						//.replace("#3", m[i].needExplain)
						.replace("#4", m[i].address)
						.replace("#5", Time)
						.replace("#6", m[i].tradeName)
						.replace("#7", m[i].needBudget)
						.replace("#8", m[i].needId)
						.replace("#9", m[i].needId)
						.replace("#2", i+1)
				}else{
				item += pattern
					.replace("#0", Status)
					.replace("#1", m[i].needName)
					//.pattern.replace("#2", data[i].)仪器图片链接
					//.replace("#3", m[i].needExplain)
					.replace("#4", m[i].address)
					.replace("#5", undefined)
					.replace("#6", m[i].tradeName)
					.replace("#7", m[i].needBudget)
					.replace("#8", m[i].needId)
					.replace("#9", m[i].needId)
					.replace("#2", i+1)
				}
			}
			$("#needList").html(item);
		}
	})
}